<!-- 结算单生成对账表. -->
<template>
    <div>
 <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="4" :collapse="collapse" labelWidth="110" @filterChange="changeHandle"></TopFilter>
        
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :isSelectColumn="false"
      columnsRef="AuthQueryDealerysy"
    > 
    <template slot="controls" slot-scope="props">
      <multiuse-button type="primary" :click="exportFileBtn.bind()">导出</multiuse-button>
    </template>
    </FilterTable>
      <BaseDialog :visible.sync="selectDelearFlag" :title="'经销商选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
        <DealerList @close="Delearclose" @save="Delearsave"></DealerList>
      </BaseDialog>
      </div>
</template>
<script>
import moment from "moment";
import DealerList from '@/pages/claimDemage/tools/DealerList.vue';
import {getListByPage, getListForExport,exporturl} from '@/api/claim/factory/SettlementAndReconciliation';
import { getClaim } from '@/api/dictionary/index';
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils/index';
    export  default{
        mixins: [dictionary],
        components: {
        DealerList
        },
        data(){
            return{
                topFilterInit: this.topFilterInitFun(),
                fetchParams: {xhrAbort: true},    
                selectDelearFlag: false,
                collapse: true,
                columns: this.creatHeader(),
                fetchapi: getListByPage
            };
        },
  created() {
     

  },

    methods:{
          SelectDelear() {
      this.selectDelearFlag = true;
    },
    //选中
      selectChange(rows) {
        this.selectedRows = rows;
        console.log(this.selectedRows);
      },

       // 导出
   async exportFileBtn() {
      let json = Object.assign({}, { CODE: 'CODE_00000246' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // getListForExport(this.fetchParams).then(res => {
      //   exportExcelFile(res.data, '结算单生成对账表');
      // });
    },
     Delearclose() {
      this.selectDelearFlag = false;
    },
    //保存
    Delearsave(obj) {
      this.topFilterInit.map(x => {
        if ('ownerCode' == x.fieldName) {
          x.initialValue = obj[0].dealerCode; 
        }
      })
      this.selectDelearFlag = false;

    },
 
    //搜索获取数据
    changeHandle(val) {
      /*刷新表格 用它*/
      this.fetchParams = Object.assign({}, this.fetchParams, val,{xhrAbort:false});
      console.log(this.fetchParams);
    },
    //搜索数据
    topFilterInitFun() {
       return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'ownerCode',
          placeholder: '请输入',
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.SelectDelear()} />
              </div>
            );
          }
        },
         {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '',
          initialValue: '',
          
        },
         { type: 'RANGE_DATE', label: '结算单生成时间', fieldName: 'beginSettleAt|endSettleAt', placeholder: '请输入', initialValue: [
            moment()
              .startOf('week')
              .format('YYYY-MM-DD HH:mm:ss'),
            moment()
              .endOf('week')
              .format('YYYY-MM-DD HH:mm:ss')
          ],
          rules: [{ required: true, message: '请选择日期', trigger: 'change' }]  },
      ];
    },
      creatHeader() {
      //   const cParam = {
      //   summationUnit: '元',
      //   numberFormat: true,
      //   summation: true,
      //   precision: 2
      // };
        return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
              title: '经销商代码',
              dataIndex: 'ownerCode',
              sorter: true,
        },
        {
              title: '经销商简称',
              dataIndex: 'dealerShortname',
              sorter: true,
        },
        {
              title: '经销商名称',
              dataIndex: 'dealerName',
              sorter: true,
        },
        {
              title: '正常保修费用',
              dataIndex: 'zcbx',
              sorter: true,
              ...cParam,
        },
        {
              title: '服务活动费用',
              dataIndex: 'fwhd',
              sorter: true,
              ...cParam,
        },
        {
              title: '保养费用',
              dataIndex: 'byfy',
              sorter: true,
              ...cParam,
        },
        {
              title: 'PDI费用',
              dataIndex: 'pdi',
              sorter: true,
              ...cParam,
        },
        {
              title: '技术升级',
              dataIndex: 'jssj',
              sorter: true,
              ...cParam,
        },
        {
              title: '售前索赔费用',
              dataIndex: 'sqsp',
              sorter: true,
              ...cParam,
        },
        {
              title: '喷漆保修费用',
              dataIndex: 'pqsp',
              sorter: true,
              ...cParam,
        },
        {
              title: '善意补偿费用',
              dataIndex: 'eybc',
              sorter: true,
              ...cParam,
        },
        {
              title: '让渡服务',
              dataIndex: 'rdfw',
              sorter: true,
              ...cParam,
        },
        {
              title: '配件缺失索赔',
              dataIndex: 'pjqssp',
              sorter: true,
              ...cParam,
        },
        {
              title: '自费配件索赔',
              dataIndex: 'zfpjsp',
              sorter: true,
              ...cParam,
        },
        {
              title: '运费费用',
              dataIndex: 'yf',
              sorter: true,
              ...cParam,
        },
        {   title: '考核费用', 
            dataIndex: 'assessAmount', 
            sorter: true,
            ...cParam,
        },
        { 
              title: '考核原因',
               dataIndex: 'assessReason', 
               sorter: true },
        {   title: '未结算申请金额汇总', 
            dataIndex: 'col1', 
            sorter: true,
        },
        {   title: '已结算申请金额汇总', 
            dataIndex: 'col2', 
            sorter: true,
        },
        {   title: '已结算申请未开发票金额汇总', 
            dataIndex: 'col3', 
            sorter: true,
        },
        {   title: '已开发票金额汇总', 
            dataIndex: 'col4', 
            sorter: true,
        },


        ];
                const cParam = {
        summationUnit: '元',
        numberFormat: true,
        summation: true,
        precision: 2
      };
      },

  },
};
 </script>
<style lang="less" scoped></style>   
